package com.ruoyi.zsyh.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zsyh.domain.ZsyhAfterFactoryMenu;
import com.ruoyi.zsyh.service.IZsyhAfterFactoryMenuService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.domain.Ztree;

/**
 * 厂家售后菜单管理Controller
 * 
 * @author yuexl
 * @date 2022-09-26
 */
@Controller
@RequestMapping("/zsyh/afterFactoryMenu")
public class ZsyhAfterFactoryMenuController extends BaseController
{
    private String prefix = "zsyh/afterFactoryMenu";

    @Autowired
    private IZsyhAfterFactoryMenuService zsyhAfterFactoryMenuService;

    @RequiresPermissions("zsyh:afterFactoryMenu:view")
    @GetMapping()
    public String afterFactoryMenu()
    {
        return prefix + "/afterFactoryMenu";
    }

    /**
     * 查询厂家售后菜单管理树列表
     */
    @RequiresPermissions("zsyh:afterFactoryMenu:list")
    @PostMapping("/list")
    @ResponseBody
    public List<ZsyhAfterFactoryMenu> list(ZsyhAfterFactoryMenu zsyhAfterFactoryMenu)
    {
        List<ZsyhAfterFactoryMenu> list = zsyhAfterFactoryMenuService.selectZsyhAfterFactoryMenuList(zsyhAfterFactoryMenu);
        return list;
    }

    /**
     * 导出厂家售后菜单管理列表
     */
    @RequiresPermissions("zsyh:afterFactoryMenu:export")
    @Log(title = "厂家售后菜单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZsyhAfterFactoryMenu zsyhAfterFactoryMenu)
    {
        List<ZsyhAfterFactoryMenu> list = zsyhAfterFactoryMenuService.selectZsyhAfterFactoryMenuList(zsyhAfterFactoryMenu);
        ExcelUtil<ZsyhAfterFactoryMenu> util = new ExcelUtil<ZsyhAfterFactoryMenu>(ZsyhAfterFactoryMenu.class);
        return util.exportExcel(list, "厂家售后菜单管理数据");
    }

    /**
     * 新增厂家售后菜单管理
     */
    @GetMapping(value = { "/add/{id}", "/add/" })
    public String add(@PathVariable(value = "id", required = false) String id, ModelMap mmap)
    {
        if (StringUtils.isNotNull(id))
        {
            mmap.put("zsyhAfterFactoryMenu", zsyhAfterFactoryMenuService.selectZsyhAfterFactoryMenuById(id));
        }
        return prefix + "/add";
    }

    /**
     * 新增保存厂家售后菜单管理
     */
    @RequiresPermissions("zsyh:afterFactoryMenu:add")
    @Log(title = "厂家售后菜单管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZsyhAfterFactoryMenu zsyhAfterFactoryMenu)
    {
        return toAjax(zsyhAfterFactoryMenuService.insertZsyhAfterFactoryMenu(zsyhAfterFactoryMenu));
    }

    /**
     * 修改厂家售后菜单管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ZsyhAfterFactoryMenu zsyhAfterFactoryMenu = zsyhAfterFactoryMenuService.selectZsyhAfterFactoryMenuById(id);
        mmap.put("zsyhAfterFactoryMenu", zsyhAfterFactoryMenu);
        return prefix + "/edit";
    }

    /**
     * 修改保存厂家售后菜单管理
     */
    @RequiresPermissions("zsyh:afterFactoryMenu:edit")
    @Log(title = "厂家售后菜单管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZsyhAfterFactoryMenu zsyhAfterFactoryMenu)
    {
        return toAjax(zsyhAfterFactoryMenuService.updateZsyhAfterFactoryMenu(zsyhAfterFactoryMenu));
    }

    /**
     * 删除
     */
    @RequiresPermissions("zsyh:afterFactoryMenu:remove")
    @Log(title = "厂家售后菜单管理", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{id}")
    @ResponseBody
    public AjaxResult remove(@PathVariable("id") String id)
    {
        return toAjax(zsyhAfterFactoryMenuService.deleteZsyhAfterFactoryMenuById(id));
    }

    /**
     * 选择厂家售后菜单管理树
     */
    @GetMapping(value = { "/selectAfterFactoryMenuTree/{id}", "/selectAfterFactoryMenuTree/" })
    public String selectAfterFactoryMenuTree(@PathVariable(value = "id", required = false) String id, ModelMap mmap)
    {
        if (StringUtils.isNotNull(id))
        {
            mmap.put("zsyhAfterFactoryMenu", zsyhAfterFactoryMenuService.selectZsyhAfterFactoryMenuById(id));
        }
        return prefix + "/tree";
    }

    /**
     * 加载厂家售后菜单管理树列表
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Ztree> treeData()
    {
        List<Ztree> ztrees = zsyhAfterFactoryMenuService.selectZsyhAfterFactoryMenuTree();
        return ztrees;
    }
}
